package com.example.demo;

public class LeeCode {
    public static void main(String[] args) {
        int [] array = new int[]{2,5,1,3,4,7};
        int n = 3;
        int [] newArray = new LeeCode().shuffle2(array,n);
        for(int a : newArray){
            System.out.print(a + ",");
        }
    }
    public int[] shuffle(int[] nums, int n) {
        int index = 0;
        int [] array = new int[nums.length];
        for(int i=0; i<n; i++){
            array[index++] = nums[i];
            array[index++] = nums[i+n];
        }
        return array;
    }

    public int[] shuffle2(int[] nums, int n) {
        int [] array = new int[nums.length];
        for(int i=0; i<2*n; i++){
            if(i%2 == 0) {
                array[i] = nums[i/2];
            }else {
                array[i] = nums[(i-1)/2 + n];
            }
        }
        return array;
    }
}
